package org.aurora.model.entity;

import java.io.Serializable;
import java.util.Date;
import java.util.Objects;
import java.util.Set;

public class SchedulerInfo implements Serializable {
    public SchedulerInfo(String ip, int port) {
        this.ip = ip;
        this.port = port;
        this.address = ip + ":" + port;
    }

    /**
     * 地址 ip + : + + port
     */
    private String address;

    private String ip;

    private int port;

    /**
     * 上报时间
     */
    private Date reportTime;

    /**
     * 调度 hash 槽
     */
    private Set<Integer> hashSlots;

    /**
     * 状态
     */
    private int state;

    public String getAddress() {
        if (address == null) {
            address = ip + ":" + port;
        }
        return address;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public int getPort() {
        return port;
    }

    public void setPort(int port) {
        this.port = port;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Date getReportTime() {
        return reportTime;
    }

    public void setReportTime(Date reportTime) {
        this.reportTime = reportTime;
    }

    public Set<Integer> getHashSlots() {
        return hashSlots;
    }

    public void setHashSlots(Set<Integer> hashSlots) {
        this.hashSlots = hashSlots;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        SchedulerInfo that = (SchedulerInfo) o;
        return port == that.port && Objects.equals(ip, that.ip);
    }

    @Override
    public String toString() {
        return "SchedulerInfo{" +
                "address='" + address + '\'' +
                ", ip='" + ip + '\'' +
                ", port=" + port +
                ", reportTime=" + reportTime +
                ", hashSlots=" + hashSlots +
                ", state=" + state +
                '}';
    }
}
